package xyz.zdsoft.training_manage_system.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import xyz.zdsoft.common.utils.FileUtils;

@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Value("${logoFile}")
    private String logoFilePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println("555");
        if (!registry.hasMappingForPattern("/checkcode/**")) {
            registry.addResourceHandler("/checkcode/**").addResourceLocations("file:" + FileUtils.mkdirscheckcode(new ApplicationHome(getClass())));
        }
        if (!registry.hasMappingForPattern("/logo/**")) {
            registry.addResourceHandler("/logo/**").addResourceLocations("file:" + logoFilePath);
        }
        if (!registry.hasMappingForPattern("/doc.html")) {
            registry.addResourceHandler("/doc.html")
                    .addResourceLocations("classpath:/META-INF/resources/");
        }
        if (!registry.hasMappingForPattern("/webjars/**")) {
            registry.addResourceHandler("/webjars/**")
                    .addResourceLocations("classpath:/META-INF/resources/webjars/");
        }

    }

}
